package com.yth.util;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.Objects;

/**
 * @author yutianhong
 * @version 1.0
 * @since 2024/11/8 14:25
 */
public class AssertUtils {

    public static void isTrue(boolean expression) {
        isTrue(expression, "expected to be true, actual: " + expression);
    }

    public static void equals(Object expected, Object actual) {
        isTrue(Objects.equals(expected, actual), "expected: " + expected + ", actual: " + actual);
    }

    public static void notNull(Object object) {
        isTrue(Objects.nonNull(object), "expected not to be null, actual: " + object);
    }

    public static void notBlank(String str) {
        isTrue(StringUtils.isNotBlank(str), "expected non-blank string, actual: " + str);
    }

    public static void notEmpty(Collection<?> collection) {
        isTrue(CollectionUtils.isNotEmpty(collection), "expected non-empty collection, actual: " + collection);
    }

    private static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new IllegalArgumentException(message);
        }
    }

}
